<template>
  <div id="app-container" style="padding:30px;">
    <el-form label-width="130px">
      <el-form-item label="姓名">
        <el-col :span="5">
          <el-input v-model="copyrightin.name"/>
        </el-col>
      </el-form-item>
      <el-form-item label="手机号">
        <el-col :span="5">
          <el-input v-model="copyrightin.telephone"/>
        </el-col>
      </el-form-item>
      <!-- TODO 分类 -->
      <!-- TODO 版权 -->
      <!-- TODO 批次 -->
      <!-- TODO 书单 -->
      <el-form-item label="出生日期">
        <el-date-picker
          v-model="copyrightin.birthday"
          type="datetime"
          placeholder="选择时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
        <el-form-item label="性别">
          <el-select v-model="copyrightin.sex" clearable placeholder="请选择">
            <el-option :value="1" label="男 "/>
            <el-option :value="0" label="女"/>
          </el-select>
        </el-form-item>
        <el-form-item label="座机号">
          <el-col :span="5">
            <el-input v-model="copyrightin.phone"/>
          </el-col>
        </el-form-item>
        <el-form-item label="公司地址">
          <el-col :span="5">
            <el-input v-model="copyrightin.address"/>
          </el-col>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-col :span="5">
            <el-input v-model="copyrightin.email"/>
          </el-col>
        </el-form-item>
        <el-form-item label="备注">
          <el-col :span="5">
            <el-input v-model="copyrightin.remark"/>
          </el-col>
        </el-form-item>
        <!-- TODO 书封 -->
        <el-form-item>
          <el-button :disabled="saveBtnDisabled" type="primary" @click="updateMan()">保存</el-button>
        </el-form-item>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import copyrightin from '@/api/copyrightin/copyrightin.js'
    export default {
      data() {
        return {
          copyrightin: {
            id: 0
          },
          saveBtnDisabled: false
        }
      },
      created() {
        this.init()

      },
      methods:{
        init() { // ## 初始化
                 // ## 判断路径中是否存在id值
          if (this.$route.params && this.$route.params.id) {
            // ## 从路径中获取id值
            const id = this.$route.params.id
            // ##调用回显方法
            this.getManById(id)
          }
        },
        getManById(id) { // ## 回显
          copyrightin.getManById(id)
            .then(response => {
              this.copyrightin = response.data.man
            })
        },
        updateMan() { // ## 修改书籍
          this.saveBtnDisabled = true // ##禁用保存按钮
          copyrightin.updateMan(this.copyrightin)
            .then(response => {
              // ## 提示信息
              this.$message({
                type: 'success',
                message: '修改成功!'
              })
              // ## 回到list页面,重定向功能
              this.$router.push('/copyrightin/copyrightin/ManList')
            })
        }
      }

    }
</script>

<style scoped>

</style>
